package com.sgy.Rocketmq;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.springframework.beans.factory.annotation.Value;

public class SyncProducer01 {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("group1");
        producer.setNamesrvAddr("10.10.4.64:9876");
        producer.setInstanceName("producer");
        producer.start();
        for (int i = 0; i < 100; i++) {
            Message msg = new Message("TopicTest2" /* Topic 消息所属的topic */,
                    "TagA" /* Tag */,
                    ("Hello RocketMQ " +
                            i).getBytes(RemotingHelper.DEFAULT_CHARSET) /* Message body */);
            SendResult send = producer.send(msg);
            System.out.printf("%s%n",send);
            System.out.println();
        }
        producer.shutdown();
    }
}
